#include "bsp_bluetooth.h"

extern void do_control(void);

void bluetooth_init(void)
{
    COMx_InitDefine COMx_InitStructure;

    COMx_InitStructure.UART_Mode = UART_8bit_BRTx;
    COMx_InitStructure.UART_BRT_Use = BRT_Timer2;
    COMx_InitStructure.UART_BaudRate = 9600ul;
    COMx_InitStructure.UART_RxEnable = ENABLE;
    COMx_InitStructure.BaudRateDouble = DISABLE;
    UART_Configuration(UART2, &COMx_InitStructure);

    NVIC_UART2_Init(ENABLE, Priority_2);
    UART2_SW(UART2_SW_P10_P11);
    P1_MODE_IO_PU(GPIO_Pin_0 | GPIO_Pin_1);
}

void bluetooth_get_data()
{
    u8 i;
    if (COM2.RX_TimeOut > 0)
    {
        if (--COM2.RX_TimeOut == 0)
        {
            if (COM2.RX_Cnt > 0)
            {
                for (i = 0; i < COM2.RX_Cnt; i++)
                {
                    do_control();
                }
            }
            COM2.RX_Cnt = 0;
        }
    }
}